package org.basis.enhance.async.init.registy;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 异步初始化的bean registry
 *
 * @author wenpan 2023/06/11 16:04
 */
public class AsyncInitBeanRegistry {

    /**
     * 异步初始化的bean cache
     */
    private static final Map<String, String> ASYNC_BEAN_INFO_CACHE = new ConcurrentHashMap<>();

    /**
     * 注册需要异步初始化的方法到cache
     *
     * @param beanId     异步初始化所在的bean的beanId
     * @param methodName 异步初始化方法
     * @author wenpan 2023/6/11 4:09 下午
     */
    public static void registerAsyncInitBean(String beanId, String methodName) {
        if (beanId == null || methodName == null) {
            return;
        }
        ASYNC_BEAN_INFO_CACHE.put(beanId, methodName);
    }

    /**
     * 通过beanId获取该bean需要异步初始化的方法名称
     *
     * @param beanId beanId
     * @return java.lang.String
     * @author wenpan 2023/6/11 4:08 下午
     */
    public static String getAsyncInitMethodName(String beanId) {
        return beanId == null ? null : ASYNC_BEAN_INFO_CACHE.get(beanId);
    }
}
